package bb.lanxing.util.image;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView;

import bb.lanxing.R;
import bb.lanxing.common.config.ImagePostfix;
import bb.lanxing.net.ApiClientConfigs;
import bb.lanxing.util.DensityUtil;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.text.StringsKt;

public class GlideUtils {
    public static Companion companion = new Companion(null);

    public static class Companion {
        public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public void loadImage(Context context, String url, ImageView imageView) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions diskCacheStrategy2 = new RequestOptions().centerCrop().placeholder(R.color.white)
                    .error(R.color.white).diskCacheStrategy(diskCacheStrategy);
            Glide.with(context).load(url).apply(diskCacheStrategy2)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(imageView);
        }

        public void loadImage(Context context, String url, ImageView imageView, Drawable placeHolder,
                Drawable errorDraw) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions diskCacheStrategy2 = new RequestOptions().centerCrop().placeholder(placeHolder)
                    .error(errorDraw).diskCacheStrategy(diskCacheStrategy);
            Glide.with(context).load(url).apply(diskCacheStrategy2)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(imageView);
        }

        public void loadImage(Context context, int i, ImageView imageView) {
            RequestOptions diskCacheStrategy = new RequestOptions().centerCrop().placeholder(R.color.white)
                    .error(R.color.white).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
            Glide.with(context).load(i).apply(diskCacheStrategy).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadImage(Context context, Uri uri, ImageView imageView) {
            RequestOptions diskCacheStrategy = new RequestOptions().centerCrop().placeholder(R.color.white)
                    .error(R.color.white).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
            Glide.with(context).load(uri).apply(diskCacheStrategy).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadImage(Context context, Bitmap bitmap, ImageView imageView) {
            RequestOptions diskCacheStrategy = new RequestOptions().centerCrop().placeholder(R.color.white)
                    .error(R.color.white).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
            Glide.with(context).load(bitmap).apply(diskCacheStrategy)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(imageView);
        }

        public void loadImage(Context context, Bitmap bitmap, ImageView imageView, int i) {
            RequestOptions diskCacheStrategy = new RequestOptions().centerCrop().placeholder(i).error(i)
                    .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
            Glide.with(context).load(bitmap).apply(diskCacheStrategy)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(imageView);
        }

        public void loadImage(Context context, String url, ImageView imageView, int i, int i2, int i3, int i4) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions error = new RequestOptions().centerCrop().placeholder(R.color.white).error(R.color.white)
                    .override(i, i2).diskCacheStrategy(diskCacheStrategy).placeholder(i3).error(i4);
            Glide.with(context).load(url).apply(error).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadImage(Context context, String url, ImageView imageView, int i) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions error = new RequestOptions().centerCrop().placeholder(R.color.white).error(R.color.white)
                    .diskCacheStrategy(diskCacheStrategy).placeholder(i).error(i);
            Glide.with(context).load(url).apply(error).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadImage(Context context, String url, ImageView imageView, int i, int i2) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions error = new RequestOptions().placeholder(R.color.white).error(R.color.white)
                    .diskCacheStrategy(diskCacheStrategy).placeholder(i).error(i2);
            Glide.with(context).load(url).apply(error).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadCircleImage(Context context, String url, ImageView imageView, int i, int i2) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions error = new RequestOptions().apply(RequestOptions.bitmapTransform(new CircleCrop()))
                    .diskCacheStrategy(diskCacheStrategy).placeholder(i).error(i2);
            Glide.with(context).load(url).apply(error).transition(DrawableTransitionOptions.withCrossFade())
                    .into(imageView);
        }

        public void loadRoundImage(Context context, String url, ImageView imageView, int i) {
            DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC;
            if (StringsKt.startsWith(url, ApiClientConfigs.PROTOCOL_HTTP, 2, false)
                    || StringsKt.startsWith(url, "https://", 2, false)) {
                diskCacheStrategy = DiskCacheStrategy.RESOURCE;
            }
            RequestOptions diskCacheStrategy2 = new RequestOptions()
                    .apply(RequestOptions.bitmapTransform(new RoundedCorners(DensityUtil.dp2px(context, i))))
                    .placeholder(R.color.white).error(R.color.white).diskCacheStrategy(diskCacheStrategy);
            Glide.with(context).load(url).apply(diskCacheStrategy2)
                    .transition(DrawableTransitionOptions.withCrossFade()).into(imageView);
        }

        public String addPostfix(String photoUrl, String postfix) {
            String str = photoUrl;
            if (TextUtils.isEmpty(str) || StringsKt.contains((CharSequence) str, (CharSequence) "!", false)
                    || StringsKt.contains((CharSequence) str, (CharSequence) "file://", false)) {
                return photoUrl;
            }
            return photoUrl + postfix;
        }

        public String appendImagePath(String str, int i) {
            if (str != null) {
                switch (i) {
                case 3:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.CDN_IMAGE_TYPE_NEW_LIST_WEBP);
                    break;
                case 4:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.UPYUN_IMAGE_TYPE_LUSHU_COLL);
                    break;
                case 5:
                    str = GlideUtils.companion.addPostfix(str, "!discoverBanner");
                    break;
                case 6:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.UPYUN_IMAGE_TYPE_MATCH_PARENT_2X);
                    break;
                case 7:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.UPYUN_IMAGE_TYPE_ARTICLE_PUSH);
                    break;
                case 8:
                    break;
                case 9:
                    str = GlideUtils.companion.addPostfix(str, "!bangAvatar");
                    break;
                case 10:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.UPYUN_IMAGE_TYPE_MEDAL_SMALL);
                    break;
                case 11:
                    str = GlideUtils.companion.addPostfix(str, "!avatar");
                    break;
                case 12:
                    str = GlideUtils.companion.addPostfix(str, "!club.sm");
                    break;
                case 13:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.CDN_IMAGE_TYPE_ACTIVITY_LIST_WEBP);
                    break;
                case 14:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.CDN_IMAGE_TYPE_MEDAL_BIG_GENERAL);
                    break;
                case 15:
                    str = GlideUtils.companion.addPostfix(str, ImagePostfix.UPYUN_IMAGE_TYPE_CLUB_NEWS_SEMGENT);
                    break;
                default:
                    str = "";
                    break;
                }
                return str;
            }
            return "";
        }
    }
}